# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： util
Description :
Author : 'li'
date： 2021/6/21
-------------------------------------------------
Change Activity:
2021/6/21:
-------------------------------------------------
"""

import numpy as np


def calc_abc_from_line_2d(l1, l2):
    x0, y0 = l1[0], l1[1]
    x1, y1 = l2[0], l2[1]
    a = y0 - y1
    b = x1 - x0
    c = x0 * y1 - x1 * y0
    return a, b, c


def get_line_cross_point(line1, line2):
    # x1y1x2y2
    a0, b0, c0 = calc_abc_from_line_2d(*line1)
    a1, b1, c1 = calc_abc_from_line_2d(*line2)
    D = a0 * b1 - a1 * b0
    if D == 0:
        return None
    x = (b0 * c1 - b1 * c0) / D
    y = (a1 * c0 - a0 * c1) / D
    # print(x, y)
    return x, y


def get_vector_angle(vectors):
    xs = vectors[:, 0]
    ys = vectors[:, 1]
    angles = np.arctan2(ys, xs) * 180 / np.pi
    miners = np.where(angles < 0)
    angles[miners] = angles[miners] + 360
    return angles


def _main():
    vectors = np.array([[1, 0], [1, 0]])
    print(get_vector_angle(vectors))


if __name__ == '__main__':
    _main()
